package is.ru.honn.rumblr.domain;

import is.ru.honn.rumblr.factory.*;

public enum RumblrType
{
  LINK("link", LinkPostFactory.class),
  QUOTE("quote", QuotePostFactory.class),
  REGULAR("regular", RegularPostFactory.class);

  String value;
  Class<? extends PostFactory> factory;

  RumblrType(String value, Class<? extends PostFactory> factory)
  {
    if (factory == null)
    {
      throw new IllegalArgumentException("Factory does not exist");
    }
    this.value = value;
    this.factory = factory;
  }

  public Class<? extends PostFactory> getFactory()
  {
    return this.factory;
  }

  public String getValue()
  {
    return this.value;
  }

  public static RumblrType fromString(String value)
  {
    for (RumblrType type : RumblrType.values())
    {
      if (type.getValue().equalsIgnoreCase(value))
      {
        return type;
      }
    }
    throw new IllegalArgumentException("Can't find value " + value);
  }
}
